﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<style type="text/css">
    .form .formValue {
        padding-top: 1px;
        padding-bottom: 1px;
    }
</style>
<script>
    var currRowId = 0;
    var status = '@ViewBag.status';
    var number = '@ViewBag.number';
    $(function () {
        initControl();
        partsList();
    });
    function initControl() {
        var myLayout = $('#layout').layout({ resizable: false });
        myLayout.sizePane("west", 300);
        
        $('#MaterialClass1').change(function () {
            InitMaterialNOSelect($('#MaterialClass1').val());
        });
        $("input[type='radio'][name='RoughsTypeRadio']").on("click", function () {
            ifShowRoughcastSize();
        });

        $('#LconsumeShow').on("blur", function () {
            calculateLUtilization();
        });
        $('#LsNetWeightShow').on("blur", function () {
            calculateLUtilization();
        });

        $('#PconsumeShow').on("blur", function () {
            calculatePUtilization();
        });
        $('#CNetWeightShow').on("blur", function () {
            calculatePUtilization();
        });

        if (status == 'I') {
            InitMaterialNOSelect("");
        } else if (status == 'U') {
            var data = eval(@Html.Raw(ViewBag.oldEntity));

            var materialClass1 = '';
            if (data.MaterialNO.length >= 2) {
                materialClass1 = data.MaterialNO.substring(0, 2);
            }
            $('#MaterialClass1').val(materialClass1);
            InitMaterialNOSelect($('#MaterialClass1').val());
            setDataByJson("#itemContent", data);
        }
        initBindSelect("#itemContent");
        ifShowRoughcastSize();
    }
    function InitMaterialNOSelect(classid) {
        var Class2 = eval(@Html.Raw(ViewBag.materialClass2));
        $('#MaterialNO').empty();
        $("#MaterialNO").append("<option value=''>&nbsp;</option>");
        if (classid != '') {
            for (var i = 0; i < Class2.length; i++) {
                var currClassId = Class2[i].MaterialNO.substring(0, 2);
                if (currClassId == classid) {
                    $("#MaterialNO").append("<option value='" + Class2[i].MaterialNO + "'>" + Class2[i].MaterialNO + " " + Class2[i].MaterialName + "</option>");
                }
            }
        }

        $("#MaterialNO").val("");
        $("#MaterialNO").bindSelect();
    }
    function partsList() {
        var $partsList = $("#partsList");
        $partsList.dataGrid({
            url: "/BOM/Product/GetPartsJson2",
            height: $(window).height() - 120,
            colModel: [
                { label: '零件编号', name: 'FProductionNO', width: 115, align: 'left', sortable: false },
                { label: '零件名称', name: 'FProductionName', width: 166, align: 'left', sortable: false }
            ],
            pager: "#partsPager",
            sortname: 'FProductionNO asc',
            rownumbers: false,
            viewrecords: true,
            loadComplete: function () {
                var ids = $partsList.jqGrid('getDataIDs');
                var length = ids.length;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    if (status == 'I') {
                        $partsList.jqGrid('setSelection', currRowId);
                    }
                }
            },
            onSelectRow: function (rowId) {
                $('.has-error').find('i.error').remove();
                $('.has-error').removeClass("has-error");
                var rowData = $partsList.jqGrid('getRowData', rowId);
                $("#FProductionNO").val(rowData.FProductionNO);
                $("#FProductionName").val(rowData.FProductionName);
            },
            beforeSelectRow: function (rowid, e) {
                if (status != 'I') {
                    return false;
                }
            }
        });
        $("#btn_search").click(function () {
            $partsList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_cancel() {
        parent.$.detailClose();
    }
    function btn_ok() {
        submitForm();
    }
    function submitForm() {
        if ($('#FiberdirectionBox').prop("checked") == true) {
            $('#Fiberdirection').val("A");
        } else {
            $('#Fiberdirection').val(" ");
        }

        var val = $("input[type='radio'][name='RoughsTypeRadio']:checked").val();
        $('#RoughsType').val(val);

        $('#form1 input[type=text]').each(function () {
            if ($(this).attr("exception") != undefined && $(this).attr("exception") != '') {
                if ($(this).val() == $(this).attr("exception")) {
                    $(this).val('');
                }
            }
        });

        if (!$('#form1').formValid()) {
            return false;
        }
        var data = $("#form1").formSerialize();
        $.submitForm({
            url: "/BOM/Manufacture/SubmitMaterialQuotaForm?status=" + status + "&keyValue=" + number,
            param: data,
            success: function () {
                parent.reloadGrid1();
                parent.$.detailClose();
            }
        })
    }
    function calculateLUtilization() {
        if ($('#LconsumeShow').val() != '' && $('#LsNetWeightShow').val() != '') {
            $('#LUtilizationShow').val((parseFloat($('#LsNetWeightShow').val()) / parseFloat($('#LconsumeShow').val()) * 100).toFixed(2));
        } else {
            $('#LUtilizationShow').val("");
        }
    }
    function calculatePUtilization() {
        if ($('#PconsumeShow').val() != '' && $('#CNetWeightShow').val() != '') {
            $('#PUtilizationShow').val((parseFloat($('#CNetWeightShow').val()) / parseFloat($('#PconsumeShow').val()) * 100).toFixed(2));
        } else {
            $('#PUtilizationShow').val("");
        }
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        @RenderPage("~/Views/Shared/_CommonStampingList.cshtml")
    </div>
    <div class="ui-layout-center">
        <form id="form1">
            <table class="form" style="width:900px;text-align:right;margin:15px;border-bottom:2px solid #ccc;">
                <tr>
                    <td class="formValue" width="160px;">
                        <div class="btn-group dialog-title">
                            @(ViewBag.status == "U" ? "修改" : "新增")材料定额信息
                        </div>
                    </td>
                    <td class="formValue input-width-185" style="width:440px;">
                        技术更改单号 <input id="GGDH" name="MateAlterTecNO" type="text" class="form-control input-width-140" readonly="readonly" value="@ViewBag.ggdh" /> &nbsp;&nbsp;&nbsp;
                        生效日期 <input id="GGDRQ" name="MateAlterTecDate" type="text" onclick="WdatePicker()" class="form-control input-wdatepicker input-width-105" value='@DateTime.Now.ToString("yyyy-MM-dd")' />
                    </td>
                    <td style="width: 300px; padding: 5px 10px;">
                        <div class="btn-group" style="margin-right:20px;">
                            <a id="" class="btn btn-primary center-block" onclick="btn_ok()"><span class="glyphicon glyphicon-ok"></span> 确认</a>
                        </div>
                        <div class="btn-group">
                            <a id="" class="btn btn-primary center-block" onclick="btn_cancel()"><span class="glyphicon glyphicon-remove"></span> 取消</a>
                        </div>
                    </td>
                </tr>
            </table>
            <div id="itemContent" style="margin-left: 15px;margin-bottom:20px;">
                <table class="form" border="0" style="width:900px;">
                    <tr>
                        <th class="formTitle" style="width:120px;">零件编号</th>
                        <td class="formValue input-width-140" style="width:220px;">
                            <input id="CldeID" name="CldeID" type="hidden" value="" />
                            <input id="FProductionNO" name="FProductionNO" type="text" class="form-control required" readonly="readonly" value="" />
                        </td>
                        <th class="formTitle" style="width:80px;">利废零件</th>
                        <td class="formValue input-width-140" style="width:310px;">
                            <input id="WasteFProductionNO" name="WasteFProductionNO" type="text" class="form-control" value="" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">零件名称</th>
                        <td class="formValue input-width-210">
                            <input id="FProductionName" name="FProductionName" type="text" class="form-control" readonly="readonly" value="" />
                        </td>
                        <th class="formTitle">利废单位</th>
                        <td class="formValue input-width-185">
                            <select id="WasteUnit" name="WasteUnit" class="form-control">
                                <option value="">&nbsp;</option>
                                @foreach (var item in ViewBag.assembleLine)
                                {
                                    <option value="@item.MakeLineNO">@item.MakeLineNO @item.MakeLineShortName</option>
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">生产单位</th>
                        <td class="formValue input-width-185">
                            <select id="ProductUnit" name="ProductUnit" class="form-control">
                                <option value="">&nbsp;</option>
                                @foreach (var item in ViewBag.assembleLine)
                                {
                                    <option value="@item.MakeLineNO">@item.MakeLineNO @item.MakeLineShortName</option>
                                }
                            </select>
                        </td>
                        <th class="formTitle">利废车间</th>
                        <td class="formValue input-width-185">
                            <select id="WasteWorkshop" name="WasteWorkshop" class="form-control">
                                <option value="">&nbsp;</option>
                                @foreach (var item in ViewBag.assembleLine)
                                {
                                    <option value="@item.MakeLineNO">@item.MakeLineNO @item.MakeLineShortName</option>
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">车间</th>
                        <td class="formValue input-width-185">
                            <select id="ProduWorkshop" name="ProduWorkshop" class="form-control">
                                <option value="">&nbsp;</option>
                                @foreach (var item in ViewBag.assembleLine)
                                {
                                    <option value="@item.MakeLineNO">@item.MakeLineNO @item.MakeLineShortName</option>
                                }
                            </select>
                        </td>
                        <th class="formTitle">利废比例</th>
                        <td class="formValue input-width-40">
                            <input id="WasteProportion" name="WasteProportion" type="text" class="form-control text-right number" max="100" onkeyup="onlyNumber(this);" /><label class="suffix">%</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">大类</th>
                        <td class="formValue input-width-105">
                            <select id="MaterialClass1" name="MaterialClass1" class="form-control">
                                <option value="">&nbsp;</option>
                                @foreach (var item in ViewBag.materialClass1)
                                {
                                    <option value="@item.MaterialNO">@item.MaterialNO @item.MaterialName</option>
                                }
                            </select>
                        </td>
                        <th class="formTitle">毛坯类别</th>
                        <td class="formValue" rowspan="2">
                            <input id="RoughsType" name="RoughsType" type="hidden" value="" />
                            <input id="RoughsTypeRadio1" name="RoughsTypeRadio" type="radio" value="K" style="margin-left:5px" checked="checked" /><label for="kuai" class="suffix">块料</label>
                            <input id="RoughsTypeRadio2" name="RoughsTypeRadio" type="radio" value="Y" style="margin-left:5px" /><label for="yixing" class="suffix">异形</label><br />
                            <input id="RoughsTypeRadio3" name="RoughsTypeRadio" type="radio" value="T" style="margin-left:5px" /><label for="tiao" class="suffix">条料</label>
                            <input id="RoughsTypeRadio4" name="RoughsTypeRadio" type="radio" value="L" style="margin-left:5px" /><label for="luo" class="suffix">落料</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">材料分类</th>
                        <td class="formValue input-width-105">
                            <select id="MaterialNO" name="MaterialNO" class="form-control">
                            </select>
                        </td>
                        <th class="formTitle">&nbsp;</th>
                    </tr>
                    <tr>
                        <th class="formTitle">材料牌号</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialCode" name="MaterialCode" type="text" class="form-control" />
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue">
                            <div class="category-0">&nbsp; 方向&nbsp;&nbsp; 宽度&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 长度&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 件数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 搭边</div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">材料规格</th>
                        <td class="formValue input-width-40">
                            <input id="MaterialSizes" name="MaterialSizes" type="hidden" class="" value="" />
                            <input id="MaterialSizes1" name="MaterialSizes1" type="text" class="form-control text-right number" integral-length="2" fractional-length=2 maxlength="5" /><label class="suffix" style="font-size:18px;">&times;</label>
                            <input id="MaterialSizes2" name="MaterialSizes2" type="text" class="form-control text-right digits" maxlength="4"  /><label class="suffix" style="font-size:18px;">&times;</label>
                            <input id="MaterialSizes3" name="MaterialSizes3" type="text" class="form-control text-right digits" exception='C' maxlength="5" />
                        </td>
                        <th class="formTitle">毛坯尺寸</th>
                        <td class="formValue input-width-240">
                            <div class="category-0">
                                <input id="Fiberdirection" name="Fiberdirection" type="hidden" class="" value="" />
                                <input id="FiberdirectionBox" name="FiberdirectionBox" type="checkbox" class="" style="margin:0 10px;" />
                                <input id="RoughsSize" name="RoughsSize" type="hidden" class="" value="" />
                                <input id="RoughsSize1" name="RoughsSize1" type="text" class="form-control text-right number" maxlength="6" integral-length="4" fractional-length="1" style="width: 50px !important; margin: 0 5px;" /><label class="suffix" style="font-size:18px;">&times;</label>
                                <input id="RoughsSize2" name="RoughsSize2" type="text" class="form-control text-right number" maxlength="6" integral-length="4" fractional-length="1" style="width: 50px !important; margin: 0 5px;" /><label class="suffix" style="font-size:18px;">/</label>
                                <input id="RoughsSize3" name="RoughsSize3" type="text" class="form-control text-right digits" maxlength="2" style="width: 30px !important; margin: 0 5px;" /><label class="suffix" style="font-size:18px;">+</label>
                                <input id="RoughsSize4" name="RoughsSize4" type="text" class="form-control text-right number" maxlength="5" integral-length="3" fractional-length="1" style="width: 40px !important; margin: 0 5px;" />
                            </div>
                            <div class="category-1">
                                <input id="RoughsSize5" name="RoughsSize5" type="text" class="form-control" maxlength="50" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">标准编号</th>
                        <td class="formValue input-width-105">
                            <input id="StandardNumber" name="" type="text" class="form-control" />
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue">
                            <div class="category-0">
                                上公差<input id="WposiTolerance" name="WposiTolerance" type="text" class="form-control text-right number" style="width: 50px !important; margin: 0 5px;" /><label class="suffix" style="font-size:18px;"> &nbsp;&nbsp;</label>
                                <input id="HposiTolerance" name="HposiTolerance" type="text" class="form-control text-right number" style="width: 50px !important; margin: 0 5px;" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">特殊要求</th>
                        <td class="formValue input-width-210">
                            <input id="MaterialDemand" name="MaterialDemand" type="text" class="form-control" />
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue">
                            <div class="category-0">
                                下公差<input id="WnegaTolerance" name="WnegaTolerance" type="text" class="form-control text-right number" style="width: 50px !important; margin: 0 5px;" /><label class="suffix" style="font-size:18px;"> &nbsp;&nbsp;</label>
                                <input id="HnegaTolerance" name="HnegaTolerance" type="text" class="form-control text-right number" style="width: 50px !important; margin: 0 5px;" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">零件可制件数</th>
                        <td class="formValue input-width-80">
                            <input id="ProduNumber" name="ProduNumber" type="text" class="form-control text-right digits" onkeyup="onlyDigital(this);" /><label class="suffix">件</label>
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">毛坯剪切规格</th>
                        <td class="formValue input-width-40">
                            <input id="Roughsstandard1" name="Roughsstandard1" type="text" class="form-control text-right number" maxlength="7" integral-length="4" fractional-length="2" /><label class="suffix" style="font-size:18px;">&times;</label>
                            <input id="Roughsstandard2" name="Roughsstandard2" type="text" class="form-control text-right number" maxlength="7" integral-length="4" fractional-length="2" />
                        </td>
                        <th class="formTitle">落料片重量</th>
                        <td class="formValue input-width-80">
                            <input id="MaterialQuotaShow" name="MaterialQuota" type="text" class="form-control text-right number" /><label class="suffix">Kg</label>
                        </td>
                    </tr>
                </table>
                <table class="form" style="width:900px;">
                    <tr>
                        <th class="formTitle" style="width:120px;">零件毛重</th>
                        <td class="formValue input-width-80" style="width:110px">
                            <input id="LRoughsWeightShow" name="LRoughsWeight" type="text" class="form-control text-right number" /><label class="suffix">Kg</label>
                        </td>
                        <th class="formTitle" style="width:70px;">零件消耗</th>
                        <td class="formValue input-width-80" style="width:110px">
                            <input id="LconsumeShow" name="Lconsume" type="text" class="form-control text-right number" /><label class="suffix">Kg</label>
                        </td>
                        <th class="formTitle" style="width:70px;">零件净重</th>
                        <td class="formValue input-width-80">
                            <input id="LsNetWeightShow" name="LsNetWeight" type="text" class="form-control text-right number" /><label class="suffix">Kg</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">产品毛重</th>
                        <td class="formValue input-width-80">
                            <input id="CRoughsWeightShow" name="CRoughsWeight" type="text" class="form-control text-right number" /><label class="suffix">Kg</label>
                        </td>
                        <th class="formTitle">产品消耗</th>
                        <td class="formValue input-width-80">
                            <input id="PconsumeShow" name="Pconsume" type="text" class="form-control text-right number" /><label class="suffix">Kg</label>
                        </td>
                        <th class="formTitle">产品净重</th>
                        <td class="formValue input-width-80">
                            <input id="CNetWeightShow" name="CNetWeight" type="text" class="form-control text-right number" /><label class="suffix">Kg</label>
                        </td>
                    </tr>
                </table>
                <table class="form" style="width:900px;">
                    <tr>
                        <th class="formTitle" style="width:120px;">零件材料利用率</th>
                        <td class="formValue input-width-40" style="width:210px;">
                            <input id="LUtilizationShow" name="LUtilization" type="text" class="form-control text-right" readonly="readonly" /><label class="suffix">%</label>
                        </td>
                        <th class="formTitle" style="width:120px;">&nbsp;</th>
                        <td class="formValue input-width-80">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">产品材料利用率</th>
                        <td class="formValue input-width-40">
                            <input id="PUtilizationShow" name="PUtilization" type="text" class="form-control text-right" readonly="readonly" /><label class="suffix">%</label>
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue input-width-80">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">代用材料</th>
                        <td class="formValue input-width-210">
                            <input id="SubstitMaterial" name="SubstitMaterial" type="text" class="form-control" maxlength="50" />
                        </td>
                        <th class="formTitle">备注说明</th>
                        <td class="formValue input-width-280">
                            <input id="Note" name="Note" type="text" class="form-control" maxlength="50" />
                        </td>
                    </tr>
                </table>
            </div>
        </form>
    </div>
</div>



